package com.example.sysao.controller;

import com.example.sysao.pejo.Technician;
import com.example.sysao.service.ReapirService;
import com.example.sysao.service.TechnicianService;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Component
@RequestMapping("/technician")
public class TechnicianController {
    @Resource
    private TechnicianService technicianService;
    @Resource
    private ReapirService reapirService;

    @RequestMapping("/list")
    public List<Technician> findAll() {
        return technicianService.findAll();
    }

    @DeleteMapping("/deleteTechnician/{id}")
    public Map<String, Object> deleteuser(@PathVariable("id") int id) {
        Map<String, Object> map = new HashMap<>();
        map.put("success", false);
        if (technicianService.removeTechnician(id)) {
            map.put("success", true);
        }
        return map;
    }

    @RequestMapping("/findById")
    public Technician findById(int id) {
        return technicianService.finsById(id);
    }


    @RequestMapping("/saveTechnician")
    public Map<String, Object> saveTechnician(@RequestBody Technician technician) {
        Map<String, Object> map = new HashMap<>();
        if (technicianService.saveTechnician(technician)) {
            map.put("success", true);
        }
        return map;
    }

    @PostMapping("/addTechnician")
    public Map<String, Object> addTechnician(@RequestBody Technician technician) {
        Map<String, Object> map = new HashMap<>();
        if (technicianService.addTechnician(technician)) {
            map.put("success", true);
        }
        return map;
    }

    @RequestMapping("/findByType")
    public List<Technician> findByType(String type) {
        return technicianService.findByType(type);
    }
}
